<?php

namespace app\api\model;

use think\Model;

class VideoList extends Model
{
    protected $autoWriteTimestamp = true;

    protected $pk = 'video_id';

    public static function getRecommendList()
    {
        return self::alias('a')
            ->join('video_level vl', 'a.level_id = vl.level_id')
            ->where('a.is_recommend', 1)
            ->where('a.video_status', 1)
            ->order('a.video_sort desc,a.video_id desc')
            ->field('a.*,vl.level_title')
            ->select()
            ->toArray();
    }

    public static function getListByWhere($where, $pageNo, $pageSize)
    {
        return self::alias('a')
            ->join('video_level vl', 'a.level_id = vl.level_id')
            ->where($where)
            ->order('a.video_sort desc,a.video_id desc')
            ->field('a.*,vl.level_title')
            ->page($pageNo, $pageSize)
            ->select()
            ->toArray();
    }

    public static function countListByWhere($where)
    {
        return self::alias('a')
            ->join('video_level vl', 'a.level_id = vl.level_id')
            ->where($where)
            ->count();
    }

    public static function getInfoById($videoId)
    {
        return self::alias('a')
            ->join('video_level vl', 'a.level_id = vl.level_id')
            ->where('a.video_id', $videoId)
            ->where('a.video_status', 1)
            ->find();
    }
}